package com.sanjiahantang.youjiaclient.module.me.help;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.base.BaseMvpActivity;
import com.sanjiahantang.youjiaclient.base.BaseView;
import com.sanjiahantang.youjiaclient.module.cases.beans.CaseBean;
import com.sanjiahantang.youjiaclient.module.common.presenters.SearchPresenter;
import com.sanjiahantang.youjiaclient.module.common.views.impl.SearchActivity;

import static com.sanjiahantang.youjiaclient.config.StaticValue.KEY_KEYWORDS;
import static com.sanjiahantang.youjiaclient.config.StaticValue.KEY_TYPE;
import static com.sanjiahantang.youjiaclient.config.StaticValue.SEARCH_TYPE_HELP;

/**
 * Created by zy on 2017/11/8.
 */

public class HelpCenterActivity extends BaseMvpActivity<BaseView,SearchPresenter> implements BaseView, View.OnClickListener {


    private QuickAdapter<CaseBean.Item> caseAdapter;
    private ListView lvHistory;
    private TextView cetSearch;
    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public SearchPresenter initPresenter() {
        return new SearchPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_help_center);
        cetSearch = (TextView) findViewById(R.id.cetSearch);
        cetSearch.setOnClickListener(this);
        findViewById(R.id.iv_back).setOnClickListener(this);
        findViewById(R.id.btnCancel).setVisibility(View.GONE);
        findViewById(R.id.iv_back).setVisibility(View.VISIBLE);
        lvHistory = (ListView) findViewById(R.id.lvHistory);
    }

    @Override
    public void initData() {
        loadHelpList();
    }

    private void loadHelpList() {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        lvHistory.setLayoutParams(params);
        cetSearch.setText(R.string.key_words_help_hint);
        presenter.initAdapter($this, lvHistory);
        presenter.loadHelpList($this, "");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.cetSearch:
                startActivityForResult(new Intent($this, SearchActivity.class).putExtra(KEY_TYPE,SEARCH_TYPE_HELP),1);
                break;
            case R.id.iv_back:
                finish();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == RESULT_OK){
            String keyWords = data.getStringExtra(KEY_KEYWORDS);
            if (TextUtils.isEmpty(keyWords)){
                cetSearch.setText(R.string.key_words_hint);
            }else {
                cetSearch.setText(keyWords);
            }
            presenter.loadHelpList($this, keyWords);
        }
    }
}
